package com.crr;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Productor {
    public static void main(String[] args) throws IOException, TimeoutException {
        //创建连接工厂 创建连接
        ConnectionFactory factory = new ConnectionFactory();
        factory.setVirtualHost("/");
        factory.setPort(5672);
        factory.setUsername("user");
        factory.setPassword("chen1116.");
        // factory.setHost("127.0.0.1");

        //创建连接
        Connection conn=factory.newConnection();
        //创建信道
        Channel channel=conn.createChannel();
        //声明队列
        String queueName="work";
        channel.queueDeclare(queueName,false,false, false,null);
        //发送消息
        String []msg={".","......","..","....","................"};
        for(String m:msg){
             channel.basicPublish("",queueName,null,m.getBytes());
        }

        //释放资源
        channel.close();
        conn.close();
        System.out.println("消息已发送");
    }
}
